package TestPaperSystem.mulitEditorOnline.controller;


import TestPaperSystem.Dto.PageUtils_VO;
import TestPaperSystem.mulitEditorOnline.pojo.DocumentEntity;
import TestPaperSystem.mulitEditorOnline.service.EditOnlineService;
import TestPaperSystem.utils.R;
import TestPaperSystem.utils.ResponseUtils_R;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spire.doc.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/mulit-edit_online")
public class EditorOnlineController {


    @Autowired
    private EditOnlineService editOnlineService;

    @PostMapping("/fileUpLoad")
    public R fileTurnToOnline(@RequestBody MultipartFile file, String name , String userId){
        String result;
        try {
            result = editOnlineService.saveFileAsOnlineEdit(file ,name,userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseUtils_R.error(e.getMessage());
        }
        return ResponseUtils_R.success(result);
    }

    @GetMapping("/getDocById/{id}")
    public R getDocContentById(@PathVariable String id){
        DocumentEntity content = null;
        try {
            content = editOnlineService.getDocContentById(id);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseUtils_R.error(e.getMessage());
        }

        return ResponseUtils_R.success(content);
    }


    @PostMapping("/getData")
    public R getPageData(@RequestBody PageUtils_VO page){
        Page result = null;
        try{
            result = editOnlineService.getPageData(page);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseUtils_R.error("null");
        }
        return ResponseUtils_R.success(result);
    }
}
